--
--  AppDelegate.applescript
--  Help Eject My CD
--
--  Created by Danijel James on 2/11/2013.
--  Copyright (c) 2013 Danijel James.
--  All rights reserved.
--
--  Redistribution and use in source and binary forms, with or without
--  modification, are permitted provided that the following conditions are met:
--
--  * Redistributions of source code must retain the above copyright notice, this
--  list of conditions and the following disclaimer.
--
--  * Redistributions in binary form must reproduce the above copyright notice,
--  this list of conditions and the following disclaimer in the documentation
--  and/or other materials provided with the distribution.
--
--  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
--  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
--  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
--  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
--  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
--  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
--  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
--  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
--  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
--  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

script AppDelegate
	property parent : class "NSObject"
	
	on applicationWillFinishLaunching_(aNotification)
		-- Insert code here to initialize your application before any files are opened 
	end applicationWillFinishLaunching_
    
    -- Eject CD/DVD Terminal
    on ButtonHandlerEjectCD_(sender)
        do shell script "drutil eject"
        do shell script "drutil tray eject"
        delay 10
        display dialog "The CD/DVD will now eject. If it does not successfully eject, there is probably a hardware issue with your Mac. Please contact your local Apple Store or Authorised Repair Center for further information." with title "Eject Request Sent" buttons {"OK"}
    end ButtonHandlerEjectCD_
    
    -- Show help dialog
    on ButtonHandlerShowHelp_(sender)
        display dialog "Help Eject My CD will attempt to eject any stuck CD/DVD from the tray or slimline drive of your Mac computer. Please visit my website to read about my other projects." with title "Help" with icon note buttons {"Website","OK"} default button 2
        if result = {button returned:"Website"} then
            open location "http://danijelj.com/projects/"
        end if
    end ButtonHandlerShowHelp_
    
    -- Bitcoin donation
    on ButtonHandlerBitcoinDonation_(sender)
        open location "https://coinbase.com/checkouts/21ed006ac313d994a184bba489d5e70d"
    end ButtonHandlerBitcoinDonation_

    -- Litecoin donation
    on ButtonHandlerLitecoinDonation_(sender)
        display dialog "Litecoin donation feature was not complete\nat the time of making this application. This\nfeature will be implemented in the next update." with title "Litecoin Donations" buttons {"OK"}
    end ButtonHandlerLitecoinDonation_

    -- GooglePlay Donation Box
    on ButtonHandlerGooglePlayDonate_(sender)
        display dialog "Google Play donation feature was not complete\nat the time of making this application. This\nfeature will be implemented in the next update." with title "Google Play Donations" buttons {"OK"}
    end ButtonHandlerGooglePlayDonate_

	on applicationShouldTerminate_(sender)
		-- Insert code here to do any housekeeping before your application quits 
		return current application's NSTerminateNow
	end applicationShouldTerminate_
	
end script